package com.mobile.collect.db;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.mobile.collect.beans.ExportPicInfo;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "EXPORT_PIC_INFO".
*/
public class ExportPicInfoDao extends AbstractDao<ExportPicInfo, Long> {

    public static final String TABLENAME = "EXPORT_PIC_INFO";

    /**
     * Properties of entity ExportPicInfo.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property _ID = new Property(0, Long.class, "_ID", true, "_id");
        public final static Property ParentId = new Property(1, Long.class, "parentId", false, "PARENT_ID");
        public final static Property ExportPath = new Property(2, String.class, "exportPath", false, "EXPORT_PATH");
    }

    private Query<ExportPicInfo> exportResultInfo_PicPathListQuery;

    public ExportPicInfoDao(DaoConfig config) {
        super(config);
    }
    
    public ExportPicInfoDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"EXPORT_PIC_INFO\" (" + //
                "\"_id\" INTEGER PRIMARY KEY ," + // 0: _ID
                "\"PARENT_ID\" INTEGER," + // 1: parentId
                "\"EXPORT_PATH\" TEXT);"); // 2: exportPath
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"EXPORT_PIC_INFO\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, ExportPicInfo entity) {
        stmt.clearBindings();
 
        Long _ID = entity.get_ID();
        if (_ID != null) {
            stmt.bindLong(1, _ID);
        }
 
        Long parentId = entity.getParentId();
        if (parentId != null) {
            stmt.bindLong(2, parentId);
        }
 
        String exportPath = entity.getExportPath();
        if (exportPath != null) {
            stmt.bindString(3, exportPath);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, ExportPicInfo entity) {
        stmt.clearBindings();
 
        Long _ID = entity.get_ID();
        if (_ID != null) {
            stmt.bindLong(1, _ID);
        }
 
        Long parentId = entity.getParentId();
        if (parentId != null) {
            stmt.bindLong(2, parentId);
        }
 
        String exportPath = entity.getExportPath();
        if (exportPath != null) {
            stmt.bindString(3, exportPath);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public ExportPicInfo readEntity(Cursor cursor, int offset) {
        ExportPicInfo entity = new ExportPicInfo( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // _ID
            cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1), // parentId
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2) // exportPath
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, ExportPicInfo entity, int offset) {
        entity.set_ID(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setParentId(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1));
        entity.setExportPath(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(ExportPicInfo entity, long rowId) {
        entity.set_ID(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(ExportPicInfo entity) {
        if(entity != null) {
            return entity.get_ID();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(ExportPicInfo entity) {
        return entity.get_ID() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "picPathList" to-many relationship of ExportResultInfo. */
    public List<ExportPicInfo> _queryExportResultInfo_PicPathList(Long parentId) {
        synchronized (this) {
            if (exportResultInfo_PicPathListQuery == null) {
                QueryBuilder<ExportPicInfo> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.ParentId.eq(null));
                exportResultInfo_PicPathListQuery = queryBuilder.build();
            }
        }
        Query<ExportPicInfo> query = exportResultInfo_PicPathListQuery.forCurrentThread();
        query.setParameter(0, parentId);
        return query.list();
    }

}
